package tmp;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import hiram.util.EnvUtils;
import hiram.util.bean.User;
import hiram.util.dao.EmbDataSource;

public class DBUtilsTmp {
	public static void main(String[] args) throws SQLException{
		EnvUtils.setLocalEvn();
//		jdbcDataSource dataSource = new jdbcDataSource(); 
//		dataSource.setDatabase("emb:jdbc:hsqldb:file:G:/FineReport/FineReport_7.0.3/WebReport/WEB-INF/testdb/db"); 
//		dataSource.setUser("sa"); 
//		dataSource.setPassword("");
//		System.out.println(dataSource.getConnection());
		DataSource dataSource=new EmbDataSource();
		QueryRunner run = new QueryRunner(dataSource);

		// Use the BeanListHandler implementation to convert all
		// ResultSet rows into a List of Person JavaBeans.
		ResultSetHandler<List<User>> h = new BeanListHandler<User>(User.class);

		// Execute the SQL statement and return the results in a List of
		// Person objects generated by the BeanListHandler.
		try {
			List<User> persons = run.query("SELECT * FROM TB_USER", h);
			System.out.println(persons.get(1).getName());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
